<template>
    <view class="content">
        <view class="nav">
            <view class="nav-i" :class="{active : type == 1}" @click="chooseNav(1)">牛源信息</view>
            <view class="nav-i" :class="{active : type == 2}" @click="chooseNav(2)">人力/场地信息</view>
            <!-- <view class="nav-i" :class="{active : type == 3}" @click="chooseNav(3)">场地信息</view> -->
        </view>
        <!-- type = 1、2是人力，3、4、5是场地 -->
        <block v-for="(item, index) in list" :key="index">
            <view class="item item-d u-p-t-40" v-if="type == 2 && (item.type == 1 || item.type == 2)" @click="toDetail(item)">
                <view class="top2">
                    <view class="title">{{item.title}}</view>
                    <view class="sta">{{item.type_txt}}</view>
                </view>
                <view class="price">{{item.salary}}</view>
                <view class="name">
                    {{item.contacts}} <text class="u-p-l-15">{{item.telephone}}</text>
                </view>
                <view class="down">
                    <view @click.stop="toEdit(item)">
                        <image src="../../static/icon/z-editor.png" class="z-del"></image>
                        <view>编辑</view>
                    </view>
                    <view @click.stop="del(item)">
                        <image src="../../static/icon/z-del.png" class="z-del"></image>
                        <view>删除</view>
                    </view>
                </view>
            </view>
            
            <view class="item" v-else @click="toDetail(item)">
                <!-- <view>
                    <image src="../../static/image/g_img_1.png" class="img-1"></image>
                    <image src="../../static/image/g_img_2.png" class="img-1"></image>
                </view> -->
                <view class="item-d u-p-t-30">
                    <view class="top2">
                        <view class="title">{{item.title}}</view>
                        <view class="sta" v-if="item.type_txt">{{item.type_txt}}</view>
                        <!-- <view class="sta sta2">求购</view> -->
                    </view>
                    <view class="text" v-if="item.describe">{{item.describe}}</view>
                    <view class="img-box" v-if="item.image_uri_txt.length > 0">
                        <view class="u-rela" v-for="(el, ind) in item.image_uri_txt" :key="ind" v-if="ind < 3">
                            <image :src="el.attach_uri" class="img"></image>
                            <view class="img-num" v-if="item.image_uri_txt.length > 3 && ind == 2">+{{ item.image_uri_txt.length - 3 }}</view>
                        </view>
                    </view>
                    <view class="down">
                        <view @click.stop="toEdit(item)">
                            <image src="../../static/icon/z-editor.png" class="z-del"></image>
                            <view>编辑</view>
                        </view>
                        <view @click.stop="del(item)">
                            <image src="../../static/icon/z-del.png" class="z-del"></image>
                            <view>删除</view>
                        </view>
                    </view>
                </view>
            </view>
        </block>
        
        <view style="height: 94rpx;padding-top: 30rpx;">
            <u-loadmore :status="status" v-if="status != 'loadmore'" />
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                type: 1,
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [],
            };
        },
        onShow() {
            this.list = []
            this.page = 1
            this.status = 'loadmore'
            this.getList()
        },
        onReachBottom() {
        	if(this.page == 1){return}
        	this.getList()
        },
        methods: {
            toEdit(item) {
                if (this.type == 1) {
                    this.$gTo(`/pages/calf/create?id=${item.id}`)
                }
                if (this.type == 2) {
                    this.$gTo(`/pages/people/create?id=${item.id}&type=${item.type}`)
                }
            },
            
            toDetail(item) {
                if (this.type == 1) {
                    this.$gTo(`/pages/calf/calf-detail?id=${item.id}`)
                } else {
                    // item.type = 1、2是人力，3、4、5是场地
                    if (item.type == 1 || item.type == 2) {
                        this.$gTo(`/pages/people/detail?id=${item.id}`)
                    } else {
                        this.$gTo(`/pages/people/site-detail?id=${item.id}`)
                    }
                }
            },
            
            del(item) {
                this.$confirm('确认删除吗？',()=>{
                    this.$ajax('delLnformationList', {
                        userToken: this.$getSync('userToken'),
                        id: item.id,
                        category: this.type,//1-牛源信息 2-人力信息
                    }).then(ret => {
                    	if (ret.status == 0) {
                            this.$toast('删除成功');
                            setTimeout(() => {
                                this.list = []
                                this.page = 1
                                this.status = 'loadmore'
                                this.getList()
                            }, 500)
                    	} else {
                    		this.$toast(ret.message);
                    	}
                    });
                })
            },
            
            chooseNav(num) {
                if (this.type == num) return
                this.type = num
                this.page = 1
                this.status = 'loadmore'
                this.list = []
                this.getList()
            },
            
            getList() {
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax('myLnformationList', {
            		userToken: this.$getSync('userToken'),
            		page: this.page,
            		limit: 10,
                    category: this.type,//1-牛源信息 2-人力场地
            	}).then(ret => {
            		if (ret.status == 0) {
            			if (ret.data.list.length > 0) {
            				this.list = this.list.concat(ret.data.list);
            				this.page++;
            				this.status = 'loadmore'
            			} else {
            				this.status = 'nomore'
            			}
            		} else {
            			this.$toast(ret.message);
            		}
            	});
            },
        }
    };
</script>

<style lang="scss">
    
    
    page{
        background-color: #f6f6f6;
    }
    .content{
        padding-bottom: 100px;
    }
    .nav{
        border-top: 2rpx solid #ebebeb;
        background-color: #fff;
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 20rpx;
    }
    .nav-i{
        width: calc(100vw / 2);
        padding: 30rpx 0;
        font-size: 28rpx;
        text-align: center;
    }
    .active{
        font-size: 32rpx;
        font-weight: bold;
        color: #00734c;
        border-bottom: 2rpx solid #00734c;
    }
    
    .item{
        background-color: #fff;
        border-radius: 15rpx;
        margin: 0 20rpx 20rpx;
    }
    .img-1{
        width: 90rpx;
        height: 42rpx;
    }
    .item-d{
        padding: 10rpx 30rpx 30rpx;
    }
    .top2{
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .title{
        font-size: 34rpx;
        font-weight: bold;
        word-break: break-all;
        white-space: pre-line;
        padding-right: 15rpx;
    }
    .sta{
        padding: 4rpx 15rpx;
        border-radius: 6rpx;
        font-size: 23rpx;
        color: #ff5f2b;
        background-color: #fff1ec;
    }
    .sta2{
        color: #0075ff;
        background-color: #dfeeff;
    }
    .text{
        font-size: 28rpx;
        word-break: break-all;
        white-space: pre-line;
        padding-top: 15rpx;
    }
    .img-box{
        display: flex;
        justify-content: flex-start;
        align-items: center;
        padding-top: 10rpx;
    }
    .img{
        width: 200rpx;
        height: 200rpx;
        border: 2rpx solid #dedede;
        border-radius: 10rpx;
        margin-right: 20rpx;
        box-sizing: border-box;
    }
    .img:nth-child(3n) {
        margin-right: 0;
    }
    .img-num{
        font-size: 26rpx;
        color: #fff;
        text-align: center;
        line-height: 200rpx;
        width: 200rpx;
        height: 200rpx;
        border-radius: 10rpx;
        background: rgba(0, 0, 0, .5);
        position: absolute;
        left: 0;
        top: 0;
        z-index: 1;
    }
    .down{
        font-size: 26rpx;
        color: #595b62;
        padding-top: 20rpx;
        display: flex;
        justify-content: flex-end;
        align-items: center;
    }
    .down>view{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-left: 50rpx;
    }
    .z-del{
        width: 36rpx;
        height: 36rpx;
        margin-right: 10rpx;
    }
    
    .price{
        font-size: 32rpx;
        font-weight: bold;
        color: #f62a2a;
        padding: 10rpx 0;
    }
    .name{
        font-size: 26rpx;
        color: #595b62;
    }

</style>
